/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
// 集中管理跟岗位逻辑相关的异步请求
import request from "../utils/request";
// 发布分类
export const classifyPost = (cfyObj) => {
  return request.post("classes/VueClassify", cfyObj);
};

// classifyPost().then()  //函数的返回值是什么类型的东西？Promise对象
// 加载分类
export const classifyGet = (bool) => {
  //条件查询
  let query = bool ? "" : '?where={"parent":"0-0"}';
  return request.get(`classes/VueClassify${query}`);
};

//分类编辑
export const classifyPut = (objectId, cfyObj) => {
  return request.put(`classes/VueClassify/${objectId}`, cfyObj);
};

// 企业入驻
export const companyPost = (companyObj) => {
  return request.post("classes/VueCompany", companyObj);
};

// 批量录入岗位
export const companyBatch = (classify, list) => {
  let [lv1, lv2] = classify;
  let arr = list.map((item) => {
    return {
      method: "POST",
      path: "/1.1/classes/VueJob",
      body: {
        ...item, //岗位数据
        lv1, //一级类目
        lv2: lv2 ? lv2 : "", //二级类目
      },
    };
  });
  console.log(arr);
  return request.post("batch", { requests: arr });
};

// {
//   requests:[
//     {
//       method: "POST",
//       path: "/1.1/classes/VueJob",
//       body: {
//         jobName:'前端开发',
//         salary:8000,
//         lv1:'开发', //一级类目
//         lv2:'前端开发', //二级类目
//       },
//     }
//   ]
// }

//加载岗位
export const jobGet = (page = 1, condition = {}) => {
  let skip = (page - 1) * 10;
  return request.get(`classes/VueJob`, {
    params: {
      count: 1, //开启计数
      limit: 10, //每次下发的条数
      skip,
      // where: {
      //   lv1: condition.lv1,
      // },
      where: condition,
    },
  });
};
